package com.wangjw.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.stereotype.Component;

/**
 * Created by wangjw on 18/6/19.
 */
@Aspect
@Component
public class GreetingAspect {

    @Around("execution (* com.wangjw.aop.GreetingImpl.good*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        before();
        Object result = pjp.proceed();
        after();
        return result;
    }

    @Around("@annotation(com.wangjw.aop.Tag)")
    public Object aroundAnnotation(ProceedingJoinPoint pjp) throws Throwable {
        before();
        Object result = pjp.proceed();
        after();
        return result;
    }

    private void before() {
        System.out.println("Before");
    }

    private void after() {
        System.out.println("After");
    }

    // 引入增强
    @DeclareParents(value = "com.wangjw.aop.GreetingImpl", defaultImpl = ApologyImpl.class)
    private Apology apology;
}
